package com.third.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.third.entity.InboundOrder;
import com.third.entity.InboundResult;
import com.third.entity.R;
import com.third.entity.Result;
import com.third.mapper.InBoundMap;
import com.third.mapper.InBoundMapper;
import com.third.service.InBoundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
@RestController
@RequestMapping("/inBound")
public class InBoundController {

    @Autowired
    InBoundMapper inBoundMapper;

    @Autowired
    InBoundService inBoundService;

    @Autowired
    InBoundMap inBoundMap;




    @PostMapping("/list")
    public R getList(@RequestBody HashMap<String,Object> map){
        int count =(int) inBoundService.count();
        int current =(int) map.get("current");
        int size =(int) map.get("size");
        int start =(current-1)*size;
        map.put("start",start);
        IPage<InboundResult> list=inBoundService.getList(map);
        list.setTotal(count);
        return new R(true,list);
    }

    @PostMapping("/add")
    public Result add(@RequestBody InboundOrder inboundOrder){
        inBoundMap.insert(inboundOrder);
        return Result.success();
    }


    @PutMapping("/update")
    public Result update(@RequestBody InboundOrder inboundOrder){
        inBoundMap.update(inboundOrder);
        return Result.success();
    }

    @DeleteMapping("/delete")
    public Result delete(@RequestParam Integer orderId){
        System.out.println("1008601");
        inBoundMap.delete(orderId);
        return Result.success();
    }

}
